﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BGCOP.CAVTOP.INNERDEFS;

namespace BGCOP.CAVTOP.UTCOM.WINFORMS
{
    public partial class Form2 : Form
    {
        private ManageInners MnjInner = new ManageInners();
        public List<Inner> prueba;
        public delegate void UpdateTextCallback(string text);

        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            MnjInner.Inicio();
            MnjInner.ErrInner += new EventHandler<InnerErrorEventsArgs>(MnjInner_ErrInner);
            //listBox1.DataSource = MnjInner.ListaInner;
            //listBox1.DisplayMember = "id";
            //listBox1.DisplayMember = "Numero";
        }

        void MnjInner_ErrInner(object sender, InnerErrorEventsArgs e)
        {
            //throw new NotImplementedException();
            textBox1.Invoke(new UpdateTextCallback(this.UpdateText), new object[] { e.MensajeError });
            
        }
        public void UpdateText(string text)
        {
            textBox1.AppendText(text + "\n");
            textBox1.ScrollToCaret();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            MnjInner.AddInner(Convert.ToInt32(textBox2.Text));
            listBox1.DataSource = null;
            listBox1.DisplayMember = null;
            listBox1.Items.Clear();
            listBox1.DataSource = MnjInner.ListaInner;
            listBox1.DisplayMember = "id";
            
            //listBox1.DisplayMember = "Numero";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MnjInner.ProcesaInner();
        }
    }
}
